import 'package:flutter/material.dart';

class SwitchAndCheckBoxTestPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _SwitchAndCheckBoxTestRouteState();
  }
}

class _SwitchAndCheckBoxTestRouteState
    extends State<SwitchAndCheckBoxTestPage> {
  bool _switchSelected = true; //维护单选开关状态
  bool _checkboxSelected = true; //维护复选框状态
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("单选开关和复选框"),
      ),
      body: Column(
        children: <Widget>[
          Switch(
              value: _switchSelected,
              onChanged: (value) {
                //重新构建页面
                setState(() {
                  _switchSelected = value;
                });
              }),
            Checkbox(value: _checkboxSelected, onChanged: (value){
              setState(() {
                _checkboxSelected=value;
              });
            })
        ],
      ),
    );
  }
}
